package com.example.test_01.service;

import com.example.test_01.model.FoodType;
import com.example.test_01.utils.Result;

import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

/**
 * @Desc  菜品分类相关服务实现
 */
public class FoodTypeServiceImpl implements FoodTypeService{
    @Override
    public Result Add(FoodType foodType) {
        foodType.save();
        return Result.SUCCESS;
    }

    @Override
    public Result DelFoodTypeById(int id) {
        LitePal.delete(FoodType.class,id);
        return Result.SUCCESS;
    }

    @Override
    public List<FoodType> list() {
        List<FoodType> list = LitePal.findAll(FoodType.class);
        return list;
    }

    @Override
    public List<String> GetAllName() {
        List<FoodType> list = list();
        List<String> listName = new ArrayList<>();
        for(int i = 0; i < list.size();i++){
            listName.add(list.get(i).getName());
        }
        return listName;
    }


}
